﻿Module modGoodsIssue

    Function CreateButton_GoodsIssue(ByRef oForm As SAPbouiCOM.Form, ByRef sErrDesc As String) As Long

        Try
            sFuncName = "CreateButton_GoodsIssue()"
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Startung Function", sFuncName)

            Dim oitm As SAPbouiCOM.Item = oForm.Items.Add("btnCpyFrm", SAPbouiCOM.BoFormItemTypes.it_BUTTON)
            Dim oBtn As SAPbouiCOM.Button
            oitm.Top = oForm.Items.Item("2").Top
            'oitm.Left = (oForm.Items.Item("2").Left + oForm.Items.Item("2").Width + 5) 1250000074
            oitm.Left = (oForm.Width - 120)
            oitm.Width = 90
            oitm.Height = oForm.Items.Item("2").Height
            oBtn = oitm.Specific
            oBtn.Caption = "Copy From PR"
            oitm.FromPane = 0
            oitm.ToPane = 0

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)
            CreateButton_GoodsIssue = RTN_SUCCESS

        Catch ex As Exception
            sErrDesc = ex.Message().ToString()
            Call WriteToLogFile(sErrDesc, sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            CreateButton_GoodsIssue = RTN_ERROR
        End Try

    End Function

    Function Fill_MatrixValues_GoodsIssue(ByRef oForm As SAPbouiCOM.Form, ByRef sErrDesc As String) As Long

        Dim oMatrix As SAPbouiCOM.Matrix
        ' Dim oDBDSHeader, oDBDSDetail As SAPbouiCOM.DBDataSource
        Dim iRowCount As Integer = 0


        Try

            sFuncName = "Fill_MatrixValues_GoodsIssue()"
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Startung Function", sFuncName)

            'oDBDSHeader = oForm.DataSources.DBDataSources.Item(0)
            'oDBDSDetail = oForm.DataSources.DBDataSources.Item(1)
            oMatrix = oForm.Items.Item("13").Specific

            iRowCount = oMatrix.VisualRowCount

            p_oSBOApplication.StatusBar.SetText("Please Wait While Loading the Values...", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)

            oForm.Freeze(True)

            If Not oDTSelectedRows Is Nothing And oDTSelectedRows.Rows.Count > 0 Then

                For iDTRowCount As Integer = 0 To oDTSelectedRows.Rows.Count - 1

                    'Fill the  Details

                    iRowCount = iRowCount + 1

                    oMatrix.Columns.Item("1").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(2).ToString()

                    oMatrix.Columns.Item("9").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(7).ToString()

                    oMatrix.Columns.Item("15").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(6).ToString()

                    oMatrix.Columns.Item("10001004").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(4).ToString()
                    oMatrix.Columns.Item("10001010").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(5).ToString()

                    oMatrix.Columns.Item("U_AB_BaseType").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(9).ToString()
                    oMatrix.Columns.Item("U_AB_BaseEntry").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(10).ToString()
                    oMatrix.Columns.Item("U_AB_BaseLineNum").Cells.Item(iRowCount - 1).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(11).ToString()

                    'If oMatrix.Columns.Item("0").Cells.Item(oMatrix.VisualRowCount).Specific.value <> "" Then
                    '    oMatrix.AddRow()
                    'End If


                    'oMatrix.Columns.Item("1").Cells.Item(iDTRowCount).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(2).ToString()
                    'oMatrix.Columns.Item("1").Cells.Item(iDTRowCount).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(2).ToString()
                    'oMatrix.Columns.Item("1").Cells.Item(iDTRowCount).Specific.value = oDTSelectedRows.Rows(iDTRowCount)(2).ToString()




                    ' oDBDSDetail.SetValue("LineId", oDBDSDetail.Size - 1, iDTRowCount + 1)

                    'oDBDSDetail.SetValue("1", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(2).ToString())

                    'oDBDSDetail.SetValue("OcrCode", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(4).ToString())
                    'oDBDSDetail.SetValue("OcrCode2", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(5).ToString())

                    'oDBDSDetail.SetValue("WhsCode", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(6).ToString())
                    'oDBDSDetail.SetValue("Quantity", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(7).ToString())
                    'oDBDSDetail.SetValue("PriceBefDi", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(8).ToString())
                    'oDBDSDetail.SetValue("U_BaseType", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(9).ToString())
                    'oDBDSDetail.SetValue("U_BaseEntry", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(10).ToString())
                    'oDBDSDetail.SetValue("U_BaseLineNum", oDBDSDetail.Size - 1, oDTSelectedRows.Rows(iDTRowCount)(11).ToString())


                    'oDBDSDetail.InsertRecord(oDBDSDetail.Size)

                    'oDBDSDetail.Offset = oDBDSDetail.Size - 1

                Next

                ' oMatrix.LoadFromDataSourceEx()

                p_oSBOApplication.StatusBar.SetText("Values Loaded Based on Selection", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Success)

                oForm.Freeze(False)

            End If



            Fill_MatrixValues_GoodsIssue = RTN_SUCCESS
        Catch ex As Exception
            sErrDesc = ex.Message().ToString()
            Call WriteToLogFile(sErrDesc, sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            oForm.Freeze(False)
            Fill_MatrixValues_GoodsIssue = RTN_ERROR
        End Try
    End Function

End Module
